<template>
	<view class="content">
		<!-- #ifdef H5 || APP-PLUS -->
		<view class="message-title">
			<commonTitle title="浏览记录"></commonTitle>
			<!-- <view class="clear">清除</view> -->
		</view>
		<!-- #endif -->
		<view class="list-scroll-content">
			<ygc-refresh
				@onRefresh="refreshList()" 
				@scrolltolower="addList()"
				:pullupLoadingType="loadingType"
				>
				
				<uni-swipe-action>
					<uni-swipe-action-item v-if="collectionList.length ==0">
						<image src="../../static/common/nodata-sub.png" class="nodata"></image>
					</uni-swipe-action-item>
					<uni-swipe-action-item v-for="(item,index) in collectionList" :options="item.options" :key="index"  @click="swipeClick($event,index,item.goods_id)">
						<!-- <text class="cont">{{item.content}}</text> -->
						
						<view class="goods-block">
							<!-- <view style="chose-box">
								<image src="../../static/common/chose-yes.png" class="close-img"></image>
							</view> -->
							<view class="goods-mainimg" @tap="goodDetail(item.goods_id,item.promotion)">
								<image class="goods-mainimg" :src="item.goods_image_url"></image>
							</view>
							<view class="goods-info">
								<view class="goods-name">{{item.goods_name}}</view>
								<view class="goods-price">
									<text class="money-tag">券后价￥</text>
									<text class="price">{{item.coupon_price}}</text>
									<text class="old-price">分享赚￥{{item.promotion}}</text>
								</view>
							</view>
						</view>
					</uni-swipe-action-item>
				</uni-swipe-action>
				
				
			</ygc-refresh>
		</view>
		
	</view>
</template>

<script>
	import commonTitle from'../../components/titile/title.vue'
	import ygcRefresh from '../../components/ygc-refresh/ygc-refresh.vue';
	import uniSwipeAction from '../../components/uni-swipe-action/uni-swipe-action.vue'
	import uniSwipeActionItem from '../../components/uni-swipe-action-item/uni-swipe-action-item.vue'
	export default{
		components:{
			commonTitle,
			ygcRefresh,
			uniSwipeAction,
			uniSwipeActionItem
		},
		data () {
			return {
				apptoken:"",
				pageIndex:1,
				pageSize:10,
				loadingType: 'more',
				collectionList:[],
				loadMore:false,
			}
		},
		onLoad() {
			this.apptoken = uni.getStorageSync('apptoken');
			//加载浏览记录
			this.getHistory();
			
			//
		},
		methods: {
			goodDetail(id,promotion){
				const _this = this;
				//查看商品详情
				uni.setStorage({
					key:"yongjin",
					data:promotion,
					success() {
						_this.$CommonJS.navigateTo('../goodDetail/good-detail?id='+id);
					}
				})
			},
			getHistory(){
				const _this =this;
				const list = uni.getStorageSync("HistoryFoot");
				list.forEach(item=>{
					item.options=[{
						text: '删除',
						style: {
							backgroundColor: 'rgb(255,58,49)'
						}
					}];
					item.id = item.collectId;
					_this.collectionList.push(item);
				})
			},
			swipeClick(e, index,goods_id) {
				const _this = this;
				let {
					content
				} = e
				if (content.text === '删除') {
					console.log(goods_id)
					
					const newHistory = uni.getStorageSync("HistoryFoot").filter((item)=>{
						return item.goods_id!==goods_id
					});
					uni.setStorage({
						key:"HistoryFoot",
						data:newHistory,
						success() {
							_this.collectionList.splice(index, 1);
						}
					})
					console.log(newHistory);
				} 
			
			},
			/**
			 * 下拉刷新
			 */
			refreshList () {
			  console.log('下拉刷新');
				//this.getCollectionList("refresh");
			},
			/**
			 * 上拉加载
			 */
			addList() {
				console.log('上拉加载');
				if(this.loadMore){
					return
				}
				this.loadingType = 'loading';
				//this.getCollectionList();
			},
			//公告详情
			goMessageDetail(){
				this.$CommonJS.navigateTo('./messageDetail')
			}
			
		}
		
	}
</script>

<style>
	@import url("browse-footprints.css");
</style>
